using System;
using System.Collections.Generic;
using Rogan.Utility.Common;

namespace Rogan.Data
{
	[Serializable]
	public class OrderByExpression : IDbExpression, ICloneable<OrderByExpression>, ITableResetable
	{
		private readonly List<QueryParameter> _parameters = new List<QueryParameter>();
		public DbExpressionType ExpressionType
		{
			get
			{
				return DbExpressionType.OrderyBy;
			}
		}
		public Field Field
		{
			get;
			set;
		}
		public OrderByDirection Direction
		{
			get;
			set;
		}
		internal QueryParameter[] Parameters
		{
			get
			{
				return _parameters.ToArray();
			}
		}
		public OrderByExpression(Field field) : this(field, OrderByDirection.Asc)
		{
		}
		public OrderByExpression(Field field, OrderByDirection dir)
		{
			Field = field;
			Direction = dir;
		}
		public OrderByExpression Reverse()
		{
			return new OrderByExpression(Field)
			{
				Direction = (Direction == OrderByDirection.Asc) ? OrderByDirection.Desc : OrderByDirection.Asc
			};
		}
		public OrderByExpression Clone()
		{
			return DataHelper.Clone(this) as OrderByExpression;
		}
		public void SetTable(string tName)
		{
			if (Field != null)
			{
				Field.SetTableName(tName);
			}
		}
	}
}
